//
//  DetailShopViewController.m
//  L7_test
//
//  Created by Mac on 11-12-29.
//  Copyright (c) 2011年 __MyCompanyName__. All rights reserved.
//

#import "MoreOptionsController.h"
#import "UserFeedBackController.h"
#import "Constants.h"

@implementation MoreOptionsController
@synthesize firstSectionArray;
@synthesize secondSectionArray;

- (void)viewDidLoad {
    //用代码生成tableview并关联
    moreTableView  = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 480) style:UITableViewStyleGrouped];
	moreTableView.dataSource = self;
	moreTableView.delegate = self;
	[self.view addSubview:moreTableView];
    
    NSLog(@"%@",@"3...Draw the supplier detail view");
    //设置视图title
    self.title=@"更多";
    //设置返回上一页按钮
    
    NSArray *array1 = [[NSArray alloc] initWithObjects:@"版本更新",@"清空缓存",@"我有意见",@"喜欢此应用，打分鼓励下",nil];
    NSArray *array2 = [[NSArray alloc] initWithObjects:@"关于我们",@"服务条款",@"免责声明", nil];
    self.firstSectionArray = array1;
    self.secondSectionArray = array2;
    [array1 release];
    [array2 release];

    [super viewDidLoad];
}

- (void)viewWillAppear:(BOOL)animated{
    NSLog(@"%@",@"3...Display the supplier detail view");
    //设置显示导航栏
    self.navigationController.navigationBarHidden=NO; 
}

//设置cell的高度
- (CGFloat)tableView:(UITableView *)tableView
heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50;
}

//设置为2个section
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

//设置section的行数
- (NSInteger)tableView:(UITableView *)tableView
 numberOfRowsInSection:(NSInteger)section {
    NSInteger rows = 0;
    switch (section) {
        case 0:
            rows = [firstSectionArray count];
            break;
        case 1:
            rows = [secondSectionArray count];
            break;
        default:
            break;
    }
    return rows;
}

//设置每个cell显示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView
		 cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    //设置tableview的背景颜色为白色
    [tableView setBackgroundColor:[UIColor clearColor]];
    static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
							 SimpleTableIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc]
				 initWithStyle:UITableViewCellStyleDefault
				 reuseIdentifier:SimpleTableIdentifier] autorelease];
        //设置cell的背景颜色为白色
        [cell setBackgroundColor:[UIColor clearColor]];
    }
    NSString *cellText = nil;
    switch (indexPath.section) {
        case 0:
            cellText = [firstSectionArray objectAtIndex:indexPath.row];
            break;
        case 1:
            cellText = [secondSectionArray objectAtIndex:indexPath.row];
            break;
        default:
            break;
    }
    cell.textLabel.text = cellText;
    return cell;
}
//cell的点击事件
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSIndexPath *indexPath1 = [NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section];
    UITableViewCell *cell1 = [tableView cellForRowAtIndexPath:indexPath1];
    NSString *cellText1 = [NSString stringWithString: cell1.textLabel.text];
    if (indexPath.section == 0 && indexPath.row == 3) {
        NSString *str = [NSString stringWithFormat: 
                         @"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%d", 
                         APP_ID ];  
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    }

    if(cellText1 == @"我有意见"){
        [self showShopMenuAction];
    }
//    [indexPath1 release];
//    [cell1 release];
//    [cellText1 release];
}

-(void)showShopMenuAction {
    //创建新的试图并将试图推入栈中
    UserFeedBackController *userFeedBackController = [[UserFeedBackController alloc] init];
    UINavigationController  *theNavController = [[UINavigationController alloc]
                                                 initWithRootViewController:userFeedBackController];
    [userFeedBackController release];
    theNavController.navigationBar.tintColor = [UIColor blackColor];
    [self.navigationController pushViewController: userFeedBackController animated:YES];
    [theNavController release];
}

//-(IBAction)showShopMenuAction:(id)sender {
//    //创建新的试图并将试图推入栈中
//    UserFeedBackController *userFeedBackController = [[UserFeedBackController alloc]initWithNibName:@"UserFeedBackController" bundle:nil];
//    UINavigationController  *theNavController = [[UINavigationController alloc]
//                                                 initWithRootViewController:userFeedBackController];
//    [userFeedBackController release];
//    theNavController.navigationBar.tintColor = [UIColor blackColor];
//    [self.navigationController pushViewController: userFeedBackController animated:YES];
//    [theNavController release];
//    
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)viewDidUnload {
	self.firstSectionArray = nil;
    self.secondSectionArray = nil;
    [super viewDidUnload];
}

- (void)dealloc {
	[firstSectionArray release];
    [secondSectionArray release];
    if (listData != nil) {
        [listData release];
    }
    [moreTableView release];
    [super dealloc];
}
@end
